package com.springmvc.study.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.springmvc.study.pojo.User;

@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("/t1")
//    http://localhost:8080/user/t1?username=jay
//    使用RequestParam注解，设置要接受的参数名
    public String test1(@RequestParam("username") String name, Model model) {
        System.out.println("接收到的参数为" + name);
        model.addAttribute("msg", name);
        return "test";
    }
//    http://localhost:8080/user/t2?id=1&name=jay&age=3
//    前端提交一个对象
    @GetMapping("/t2")
    public String test2(User user) {
        System.out.println(user);
        return "test";
    }
}
